<?php

	function curl_get($durl) {
		  $t = parse_url($durl);
		  $ch = curl_init();
		  curl_setopt($ch, CURLOPT_URL,$durl);
		  curl_setopt($ch, CURLOPT_HEADER, false);  
		  curl_setopt($ch, CURLOPT_TIMEOUT,5);
		  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");
		  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

		  $r = curl_exec($ch);
		  curl_close($ch);
		  return $r;
	}


	function curl_get_simple_type ($Machine_sn) {

		//$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id=WS70087123');
		$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id='.$Machine_sn);

		$start = strstr($page,"MachineNameOminiEncode = ");
		$start_n = strpos($start,"\";");
		

		$result = substr($start,26,($start_n-26));

		
		 $result = str_replace("+"," ",$result);
		 return urldecode($result);

	}

		function file_get_normal_type ($Machine_sn) {
		
		//$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id=WS70087123');
		//$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id='.$Machine_sn);

		
		 $url='http://support1.lenovo.com.cn/lenovo/wsi/Modules/Manage/GetMachineList.aspx?q='.$Machine_sn;
		 $lines_array=file($url); 
		 $lines_string=implode('',$lines_array); 
		// echo htmlspecialchars($lines_string); 
		$start = $lines_string;
		$start_n = strpos($lines_string,"|");
		

		$result = substr($start,0,($start_n-0));

		
		 $result = str_replace("+"," ",$result);
		 return urldecode($result);

	}

?>


<!DOCTYPE html>
<html>

<?php //  error_reporting(0); 		 ?>

	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
    <link rel="stylesheet" type="text/css" href="./1.css" />

	
	<script  type ="text/javascript" src="./1.js">
	

	
	</script>
	
	
	
	  <script type="text/javascript" language="javascript" src="./sn.js" >    </script>
	
	</head>


	<?php
	
	//echo $_REQUEST['hidden_sn'];
			$filepath="./aa.sqlite3";

			$db=new SQLite3($filepath); //打开此路径数据库文件

			$sql="select '0000000000000'"; //查询记录
	?>
			
	<?php
	
			error_reporting(E_ALL); 
			
			$pc_type_info="";//$_REQUEST['pc_type'];
			
			//$pn_info=$_REQUEST['pn'];
			
			if(isset($_REQUEST['snpn']) && !empty($_REQUEST['snpn'])) 
			{  
			$hidden_snpn=$db->escapeString(@$_REQUEST['snpn']);
			$hidden_sn=$db->escapeString(substr($hidden_snpn,0,10));
			$hidden_pn=$db->escapeString(substr($hidden_snpn,10,8));
			}
			else
			{
			$hidden_sn=$db->escapeString(@$_REQUEST['hidden_sn']);
			$hidden_pn=$db->escapeString(@$_REQUEST['hidden_pn']);
			}
			$hidden_mo=$db->escapeString(@$_REQUEST['hidden_mo']);
			$hidden_lucky=$db->escapeString(@$_REQUEST['hidden_lucky']);
			

	?>
	
<!--------------------------------------------------------------------
//																    //
//                       body										//
//																	//
--------------------------------------------------------------------->
	
	
	 
	
	<body onload="JavaScript:(document.getElementById('input_sn_id')).focus();">

	<?php   error_reporting(0); 		 ?>
	
	


	
<?php	





		
		if(isset($_REQUEST['snpn']) && !empty($_REQUEST['snpn'])) 
		{	
			if($hidden_sn!="")
			{	
			//	$db->query("INSERT INTO sn (s_t,sn,pn,mo,lucky,datetime) VALUES('M','$hidden_sn','$hidden_pn','$hidden_mo','$hidden_lucky',datetime('now','+8 hour'));)");
			}	
		}
		else
		{
			if($hidden_sn!="")
			{	
			//	$db->query("INSERT INTO sn (s_t,sn,pn,mo,lucky,datetime) VALUES('P','$hidden_sn','$hidden_pn','$hidden_mo','$hidden_lucky',datetime('now','+8 hour'));");
			}	
		}
		//end if 
		
			

			if(@$_REQUEST['action']=="del")
			{
				$db->query("DELETE FROM sn WHERE id=".round($_REQUEST['id']));
			}
			
			
			////.///////////////////////////////////////////////////////////////////////////////////////////
			
			
		$result=$db->query("SELECT type FROM snpn where snpn.sn='".$hidden_sn."' ;");
		
			$i=0;
			while( $row=$result->fetchArray(SQLITE3_ASSOC) )
			{
			echo htmlspecialchars($row['type']);
			$i++;
			}
		
		
	?>
	
	
	
	





<table border=0 cellpadding=0 cellspacing=0>



<?php
$sql_add ="";// "  where simple_type='". $pc_type_info ."' ;";


$sqlite_sql = " SELECT * FROM snpn ".$sql_add;
$result=$db->query($sqlite_sql);
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{$i++;} $sum_line = $i;
	
$sqlite_sql = "SELECT * FROM groupby_simple_type ".$sql_add;
$result=$db->query($sqlite_sql);
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{$i++;} $sum_simple_type = $i;
	
	
$sqlite_sql = "SELECT * FROM groupby_pn ".$sql_add;
$result=$db->query($sqlite_sql);
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{$i++;} $sum_pn = $i;
	
	
	
		echo "<tr valign='bottom'>";
		echo "<td bgcolor='#fb7922' colspan='1'><img src=img/blank.gif width='1' height='8'></td>";
		echo "<td bgcolor='#fb7922' colspan='2'><img src=img/blank.gif width='1' height='8'></td>";
        echo "<td bgcolor='#fb7922' colspan='1'><img src=img/blank.gif width='1' height='8'>共计&nbsp;".$sum_line."&nbsp;行</td>";
		echo "<td bgcolor='#fb7922' colspan='8'><img src=img/blank.gif width='1' height='8'>共计&nbsp;".$sum_pn."&nbsp;种</td>";
        echo "</tr>";
?>



<tr bgcolor=#f87820>
<td><img src=img/blank.gif width=40 height=1></td>
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  type		</b></td>
<td class=tabhead><img src=img/blank.gif width=40 height=6><br><b>  S_T		</b></td>
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  sn		</b></td>
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  pn   		</b></td>

<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  mo     	</b></td>
<td class=tabhead><img src=img/blank.gif width=120 height=6><br><b>  lucky      	</b></td>
<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b>      		</b></td>
<td><img src=img/blank.gif width=10 height=1></td>
</tr>



<?php
$sqlite_sql = "SELECT * FROM snpn_orderbypn where simple_type='". $pc_type_info ."' ;";

$sqlite_sql = "SELECT * FROM groupby_type ;";
$result=$db->query($sqlite_sql);

//echo $sqlite_sql;
	
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{

		echo "<tr valign='center' class='tab_tr_val' >";

		echo "<td class='tabval'><b>".htmlspecialchars($row['id'])."</b></td>";
		
		if (empty($row['simple_type']))
		{
		
	
		$simple_type = curl_get_simple_type($hidden_sn);
		
		$type =   file_get_normal_type($hidden_sn);;

		 
		
		

		$s_pl_sql = "UPDATE pn SET pn.simple_type = '".$simple_type."' WHERE pn.pn = '".$pn_info."';"; 
		$s_pl_sql = "INSERT INTO pn (pn,simple_type,type) VALUES('".$pn_info."','".$simple_type."','".$type."');";

		
		

		
		$db->query($s_pl_sql);
		
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.reload(); ";
		echo "</script>";

		
		}
		
		
		
		echo "<td class='tabval'>".htmlspecialchars($row['type'])."&nbsp;</td>";
		echo "<td class='tabval' style='color:#f00'>".htmlspecialchars($row['s_t'])."&nbsp;</td>";
		echo "<td class='tabval'>"
				."<a href='http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id="
				.htmlspecialchars($row['sn'])
				."'>"
				.htmlspecialchars($row['sn'])
				."</a>"
				."&nbsp;</td>";
		
		
		
		
				echo "<td class='tabval' style='color:#f00'>"
				."<a href='./pn_info.php?pn="
				.htmlspecialchars($row['pn'])
				."&hidden_sn="
				.htmlspecialchars($row['sn'])
				."'>"
				.htmlspecialchars($row['pn'])
				."</a>"
				."&nbsp;</td>";
				
		echo "<td class='tabval'>".htmlspecialchars($row['mo'])."&nbsp;</td>";
		echo "<td class='tabval'>".htmlspecialchars($row['lucky'])."&nbsp;</td>";
		echo "<td class='tabval'>".htmlspecialchars($row['gc'])."&nbsp;</td>";
		echo "<td class='tabval'>".htmlspecialchars($row['montior'])."&nbsp;</td>";

		echo "<td class='tabval'><a onclick=\"return confirm('".$TEXT['phonebook-sure']."');\" href='sqlite3_1.php?action=del&id=".$row['id']."'><span class='red'>["."del"."]</span></a></td>";
		echo "<td class='tabval'></td>";
		echo "</tr>";
		$i++;
		

	}

	echo "<tr valign='bottom'>";
		echo "<td bgcolor='#fb7922' colspan='3'><img src=img/blank.gif width='1' height='8'></td>";
        echo "<td bgcolor='#fb7922' colspan='8'><img src=img/blank.gif width='1' height='8'>共计&nbsp;".$i."&nbsp;行</td>";
        echo "</tr>";

		
		$db->close(); //关闭


?>
	</table>
	
	
			<script  type ="text/javascript" >
			
			
			
			</script>
	
	</body>
</html>